package com.nexgo.sound;

import com.nexgo.oaf.apiv3.device.beeper.Beeper;
import com.nexgo.payment.aop.annotation.RunOnWorkThread;
import com.nexgo.payment.api.ApiDeviceEngine;

import java.util.concurrent.TimeUnit;

/**
 * Created by xiaox on 2017/9/21.
 */

public class BeeperManager {
    private Beeper mSdkBeeper;

    public BeeperManager() {
        mSdkBeeper = ApiDeviceEngine.getInstance().getBeeper();
    }

    @RunOnWorkThread
    public void beep(Type type) {
        switch (type) {
            case NORMAL:
                mSdkBeeper.beep(100);
                break;
            case SUCCESS:
                mSdkBeeper.beep(500);
                break;
            case FAIL:
                mSdkBeeper.beep(100);
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                mSdkBeeper.beep(100);
                break;
        }
    }

    @RunOnWorkThread
    public void beep(long duration, TimeUnit timeUnit) {
        mSdkBeeper.beep((int) timeUnit.toMillis(duration));
    }

    public enum Type {
        NORMAL,
        SUCCESS,
        FAIL,
    }
}
